<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ include file="../../include/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>中奖管理</title>
<style type="text/css">
html, body {
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
}

p.spread {
	word-spacing: 50px;
	color
}
</style>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="/css/demo.css" rel="stylesheet" type="text/css" />
<script src="/scripts/boot.js" type="text/javascript"></script>
<script src="/js/jquery.form.js" type="text/javascript"></script>
</head>
<body>
	<div id="tabs1" class="mini-tabs" activeIndex="0"
		onbeforeactivechanged="onBeforeActiveChanged"
		style="width: 100%; height: 100%;" bodyStyle="padding:0;border:0;">
		<div title="中奖管理-实物">
			<div style="width: 99%;">
				<div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
					<div id="form1">
						<table style="width: 20%;">
							<tr>
								<td>
				                    <input name="productNameOrId" id="productName" emptyText="请输入商品名称或ID" class="mini-textbox"/>
				                </td>
				                <td colspan="2" align="center"><a class="mini-button" iconCls="icon-search" onClick="search()">搜索</a>&nbsp;<a
				                        class="mini-button" iconCls="icon-reload" onClick="clean()">重置</a>
				                </td>
							</tr>
						</table>
					</div>
				</div>
			</div><!-- onshowrowdetail="onShowRowDetail" -->
			<div id="datagrid1" class="mini-datagrid"
				style="width: 99%; height: 90%;" multiSelect="true"
				url="/gamblingRecord/queryObjectPrizeShow.action" idField="id"
				allowResize="true" sizeList="[10,15,20]" pageSize="10"
				 allowCellEdit="true"
				allowCellSelect="true" editNextOnEnterKey="true"
				editNextRowCell="true">
				<div property="columns">
					<div type="checkcolumn"></div>
					<div field="period" width="150" headerAlign="center" align="center"
						cellStyle="padding:0;">夺宝期号</div>
					<div field="luckyNumber" width="150" headerAlign="center" align="center"
						cellStyle="padding:0;">中奖号码</div>
					<div field="customerId" width="90" headerAlign="center" align="center"
						cellStyle="padding:0;">中奖客户ID</div>
					<div field="userName" width="150" headerAlign="center" align="center"
						cellStyle="padding:0;">客户名</div>
					<div field="buyTimeDate" width="150" align="center"
						headerAlign="center" dateFormat="yyyy-MM-dd HH:mm:ss"
						allowSort="true">购买时间</div>
					<div field="completeTimeDate" width="150" align="center"
						headerAlign="center" dateFormat="yyyy-MM-dd HH:mm:ss"
						allowSort="true">开奖时间</div>
					<div field="gamblingRecordAddressZitiEnum.text" 
						width="150" align="center" headerAlign="center">寄送方式</div>
					<div field="expressName" width="80" align="center"
						headerAlign="center">物流名称</div>
					<div field="gamblingRecordAddress.address" width="250" align="center"
						 headerAlign="center">收件信息</div>
					<div field="gamblingRecordAddressEnum.text" width="80" align="center"
						 headerAlign="center">发货状态</div>
					<div name="action" width="150" headerAlign="center" align="center"
						renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
				</div>
			</div>
		</div>
		<div title="中奖管理-虚拟">
			<div style="width: 99%;">
				<div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
					<div id="form2">
							<table style="width: 20%;">
								<tr>
									<td>
					                    <input name="productNameOrId" id="productName2" emptyText="请输入商品名称或ID" class="mini-textbox"/>
					                </td>
					                <td colspan="2" align="center"><a class="mini-button" iconCls="icon-search" onClick="search2()">搜索</a>&nbsp;<a
				                        class="mini-button" iconCls="icon-reload" onClick="clean2()">重置</a>
				                	</td>
								</tr>
							</table>
					</div>
				</div>
			</div>
			 <div id="datagrid2" class="mini-datagrid"
				style="width: 99%; height: 90%;" multiSelect="true"
				url="/gamblingRecord/queryVirtualPrizeShow.action" idField="id"
				allowResize="true" sizeList="[10,15,20]" pageSize="10">
				<div property="columns">
					<div type="checkcolumn"></div>
					<div field="period" width="150" headerAlign="center" align="center"
						cellStyle="padding:0;">夺宝期号</div>
					<div field="luckyNumber" width="150" headerAlign="center" align="center"
						cellStyle="padding:0;">中奖号码</div>
					<div field="customerId" width="150" headerAlign="center" align="center"
						cellStyle="padding:0;">中奖客户ID</div>
					<div field="userName" width="150" headerAlign="center" align="center"
						cellStyle="padding:0;">客户名</div>
					<div field="buyTimeDate" width="150" align="center"
						headerAlign="center" dateFormat="yyyy-MM-dd HH:mm:ss"
						allowSort="true">购买时间</div>
					<div field="completeTimeDate" width="150" align="center"
						headerAlign="center" dateFormat="yyyy-MM-dd HH:mm:ss"
						allowSort="true">开奖时间</div>
					<div field="virtualData.virtualKey" 
						width="150" align="center" headerAlign="center">虚拟商品key</div>
					<div field="virtualData.secret" width="150" align="center"
						headerAlign="center">虚拟商品密钥</div>
					<div name="action" width="150" headerAlign="center" align="center"
						renderer="onActionRenderer2" cellStyle="padding:0;">操作</div>
				</div>
			</div> 
		</div>
	</div>

	<script type="text/javascript">
		mini.parse();
		var grid = mini.get("datagrid1");
		var grid2 = mini.get("datagrid2");
		var form = new mini.Form("#form1");
		var form2 = new mini.Form("#form2");
		var product_grid = mini.get("product_grid");
		//var detailGrid_Form = document.getElementById("detailGrid_Form");
		var purchaseSourceWindow = mini.get("purchaseSourceWindow");
		var shippingWindow = mini.get("shippingWindow");

		var data = form.getData(); //获取表单多个控件的数据
		var json = mini.encode(data); //序列化成JSON
		grid.load({
			json : json
		}, function(data) {
		});
		
		function onActionRenderer(e) {
			var record = e.record;
			var uid = record.id;
			var rowIndex = e.rowIndex;
			if(record.gamblingRecordAddress && record.gamblingRecordAddress.isSend){
				var s = ' <a class="Edit_Button" href="javascript:detail(\''
				+ uid + '\')">详情</a>';
				return s;
			}else{
				var s = ' <a class="Edit_Button" href="javascript:sending(\'' + uid
				+ '\')" >发货</a>'
				+ ' <a class="Edit_Button" href="javascript:detail(\''
				+ uid + '\')">详情</a>';
				return s;
			}
			
		}
		
		function onActionRenderer2(e) {
			var record = e.record;
			var uid = record.id;
			var rowIndex = e.rowIndex;
			var s = '<a class="Edit_Button" href="javascript:detail2(\''
					+ uid + '\')">详情</a>';
			return s;
		}

		function onBeforeActiveChanged(e) {
			var _id = e.tab._id;
			if (_id == 1) {
				search();
			} else if (_id == 2) {
				search2();
			} else {
				search3();
			}
		}
		function search() {
			var data = form.getData(); //获取表单多个控件的数据
			var json = mini.encode(data); //序列化成JSON
			grid.load({
				json : json
			});
		}
		function search2() {
			var data = form2.getData(); //获取表单多个控件的数据
			var json = mini.encode(data); //序列化成JSON
			grid2.load({
				json : json
			});
		}
		function clean() {
	        form.reset();
	    }
		function clean2() {
	        form2.reset();
	    }
		function sending(id){
			var row = grid.getSelected();
			if (row) {
				if(row.gamblingRecordAddress && row.gamblingRecordAddress.id){
					if(confirm("请确认已经发货了？")){
						var id = row.gamblingRecordAddress.id;
						var o = new Object();
						var gamblingRecordAddress = new Object();
						gamblingRecordAddress.id = id;
						gamblingRecordAddress.isSend = 1;
						o.gamblingRecordAddress = gamblingRecordAddress;
						var json = mini.encode(o); //序列化成JSON
						//alert(json);
						var url = "<c:url value='/gamblingRecord/updateRecordAddressSubmit.action'/>";
						$.ajax({
							url : url,
							type : 'post',
							data : {
								json : json
							},
							cache : false,
							success : function(text) {
								grid.reload();
		                        mini.showTips({
		                            content: "<b>成功</b> <br/>发货成功",
		                            state: "success",
		                            x: "center",
		                            y: "center",
		                            timeout: 3000
		                        });
							},
							error : function(jqXHR, textStatus, errorThrown) {
								mini.showMessageBox({
									showModal : false,
									width : 250,
									title : "提示",
									iconCls : "mini-messagebox-warning",
									message : jqXHR.responseText,
									timeout : 3000,
									x : "right",
									y : "bottom"
								});
							}
						});
					}
				}else{
					mini.showMessageBox({
						showModal : false,
						width : 250,
						title : "提示",
						iconCls : "mini-messagebox-warning",
						message : "请编辑好收货信息和物流信息！",
						timeout : 2000
					});
				}
			}
		}
		
		function detail(id) {
	        var row = grid.getSelected();
	    	//console.log(row.id);
	        if (row) {
	            mini.open({
	                url: "<c:url value='/gamblingRecord/objectPrizeDetail.action'/>",
	                title: "中奖详情", width: 650, height:500 ,
	                onload: function () {
	                    var iframe = this.getIFrameEl();
	                    var data = {action: "edit", id: row.id};
	                    iframe.contentWindow.SetData(data);
	                },
	                ondestroy: function (action) {
	                    if (action == "save") {
	                        grid.reload();
	                        mini.showTips({
	                            content: "<b>成功</b> <br/>修改成功",
	                            state: "success",
	                            x: "center",
	                            y: "center",
	                            timeout: 3000
	                        });
	                    }
	                }
	            });
	        }
	    }
		
		function detail2(id) {
	        var row = grid2.getSelected();
	    	//console.log(row.id);
	        if (row) {
	            mini.open({
	                url: "<c:url value='/gamblingRecord/virtualPrizeDetail.action'/>",
	                title: "中奖详情", width: 650, height:500 ,
	                onload: function () {
	                    var iframe = this.getIFrameEl();
	                    var data = {action: "edit", id: row.id};
	                    iframe.contentWindow.SetData(data);
	                },
	                ondestroy: function (action) {
	                    
	                }
	            });
	        }
	    }
		
	</script>
</body>
</html>
